<template>
  <div class="serving-merchandise-add views-container">
    <div class="wlm-form">
      <div class="wlm-form-header">基本信息</div>
      <div class="wlm-form-content">
        <el-form ref="base" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
          <el-form-item label="优惠券标题" prop="couponData.name" :rules="[{ required: true, message: '请输入优惠券名称', trigger: 'blur' }]">
            <el-input v-model.trim="formFormatData.formData.couponData.name">
            </el-input>
          </el-form-item>
           <el-form-item label="优惠券副标题" prop="couponData.name">
            <el-input v-model.trim="formFormatData.formData.couponData.vice_name">
            </el-input>
          </el-form-item>
          <el-form-item label="发放总数" prop="couponData.total_num" >
            <el-input v-model.trim="formFormatData.formData.couponData.total_num">
            </el-input>
          </el-form-item>
           <el-form-item label="优惠券排序">
                    <el-input-number :controls="false" v-model.trim="formFormatData.formData.couponData.sort">
                    </el-input-number>
                </el-form-item>
          <el-form-item label="使用时间">
            <el-radio-group :disabled="isFormEdit" v-model="formFormatData.formData.couponData.expire_type" class="wlm-form-group flex-col no-top" @change="$refs[`base`].validateField('couponData.limit_time')">
              <el-radio :label="10">
                <el-form-item class="inline" label="" label-width="0" prop="couponData.limit_time" :rules="[{ required: (formFormatData.formData.couponData.expire_type === 10), message: '请选择使用时间', trigger: 'blur' }]">
                  <el-date-picker :default-time="[`${`${new Date().getHours()}`.padStart(2,'0')}:${`${new Date().getMinutes()}`.padStart(2,'0')}:00`,'23:59:59']" :disabled="isFormEdit" :picker-options="afterOptions" v-model="formFormatData.formData.couponData.limit_time" value-format="timestamp" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                  </el-date-picker>
                </el-form-item>
              </el-radio>
              <el-radio :label="20">领券后当日可用</el-radio>
              <el-radio :label="30">
                领券后次日起
                <el-form-item class="inline" label="" label-width="0" prop="couponData.expire_day" :rules="[{ required: (formFormatData.formData.couponData.expire_type === 30), message: '请选择使用时间', trigger: 'blur' }]">
                  <el-input-number :disabled="isFormEdit" style="width:80px;" :controls="false" :min="1" :precision='0' class="wlm-input-auto" v-model.trim="formFormatData.formData.couponData.expire_day">
                  </el-input-number>
                </el-form-item>
                天内可用
              </el-radio>
               <el-radio :label="40">
                            领券后当日起
                            <el-form-item class="inline" label="" label-width="0" prop="couponData.expire_day" :rules="[{ required: (formFormatData.formData.couponData.expire_type === 30), message: '请选择使用时间', trigger: 'blur' }]">
                              <!-- <el-input :disabled="isFormEdit" style="width:80px;" v-model.trim="formFormatData.formData.couponData.expire_day">
                              </el-input> -->
                              <el-input-number :disabled="isFormEdit" class="wlm-input-auto" style="width:80px;"  :controls="false" :min="0" :precision='0' v-model.trim="formFormatData.formData.couponData.expire_day">
                              </el-input-number>
                            </el-form-item>
                            天内可用
                        </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="使用门槛">
            <el-radio-group :disabled="isFormEdit" v-model="formFormatData.formData.couponData.rule" class="wlm-form-group">
              <el-radio :label="1">无门槛</el-radio>
              <el-radio :label="0">有门槛</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="" v-if="formFormatData.formData.couponData.rule === 0" prop="couponData.rule_min_money">
            <el-input :disabled="isFormEdit" width="50" v-model="formFormatData.formData.couponData.rule_min_money">
              <template slot="prepend">消费满</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="优惠内容" prop="couponData.discount">
            <el-input :disabled="isFormEdit" width="50" v-model="formFormatData.formData.couponData.discount">
              <template slot="prepend">打</template>
              <template slot="append">折</template>
            </el-input>
            <p class="form-help">优惠折扣范围 (0~10)</p>
          </el-form-item>
          <el-form-item label="发放渠道" prop="couponData.source" :rules="[{ required: true, message: '请选择渠道', validator: validateCheckArray, trigger: 'change' }]">
            <el-checkbox-group v-model="formFormatData.formData.couponData.source">
              <el-checkbox label="2" v-if="JSON.stringify($store.getters.power).indexOf('wxapp')>-1">微信小程序</el-checkbox>
                  <el-checkbox label="3" v-if="JSON.stringify($store.getters.power).indexOf('H5')>-1">H5</el-checkbox>
                  <el-checkbox label="4" v-if="JSON.stringify($store.getters.power).indexOf('wechat')>-1">微信公众号</el-checkbox>
                  <el-checkbox label="7" v-if="JSON.stringify($store.getters.power).indexOf('aliapp')>-1">支付宝小程序</el-checkbox>
                  <el-checkbox label="9" v-if="JSON.stringify($store.getters.power).indexOf('toutiaoapp')>-1">抖音-头条</el-checkbox>
              <!-- <el-checkbox label="2" v-if="$store.getters.power.includes('wxapp')">微信小程序</el-checkbox>
              <el-checkbox label="3" v-if="$store.getters.power.includes('H5')">H5</el-checkbox>
              <el-checkbox label="4" v-if="$store.getters.power.includes('wechat')">微信公众号</el-checkbox>
              <el-checkbox label="7" v-if="$store.getters.power.includes('aliapp')">支付宝小程序</el-checkbox>
              <el-checkbox label="9" v-if="$store.getters.power.includes('toutiaoapp')">抖音-头条</el-checkbox> -->
            </el-checkbox-group>
          </el-form-item>
          
          <el-form-item label="" prop="couponData.max_price" :rules="[{ required: (formFormatData.formData.couponData.max_price_type == 1), message: '请输入最多优惠金额', trigger: 'blur' }]">
            <el-checkbox :disabled="isFormEdit" v-model="formFormatData.formData.couponData.max_price_type" :true-label="1" :false-label="0" style="margin-right: 10px;">最多优惠</el-checkbox>
            <el-input-number class="wlm-input-auto" :disabled="isFormEdit" width="50" :min="0" :controls="false" :precision="2" v-model="formFormatData.formData.couponData.max_price">

            </el-input-number>
            元
          </el-form-item>
          <!-- <el-form-item label="分享转发">
                    <el-radio-group  v-model="formFormatData.formData.couponData.is_share" class="wlm-form-group">
                        <el-radio :label="1">开启</el-radio>
                        <el-radio :label="2">关闭</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="分享好友才能领取" v-if="formFormatData.formData.couponData.is_share==1">
                    <el-radio-group  v-model="formFormatData.formData.couponData.share_receive" class="wlm-form-group">
                        <el-radio :label="1">开启</el-radio>
                        <el-radio :label="2">关闭</el-radio>
                    </el-radio-group>
                </el-form-item> -->
                 <el-form-item label="优惠券详情页封面图">
                  <choose-files ref="chooseFiles" style="margin-left:20px;" :config="choosePlatformConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                  <div class="form-help">建议尺寸：750*300像素</div>
                 </el-form-item>
                 <el-form-item label="分享自定义">
                    <el-radio-group  v-model="formFormatData.formData.couponData.wxapp_share" class="wlm-form-group">
                        <el-radio :label="1">开启</el-radio>
                        <el-radio :label="2">关闭</el-radio>
                    </el-radio-group>
                </el-form-item>
                 <el-form-item label="分享图片" ref="businessbackgroundmap" v-if="formFormatData.formData.couponData.wxapp_share==1">
                    <choose-files ref="chooseFiles" :config="chooseBgConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                    <div class="form-help">推荐尺寸：750X750，尺寸不匹配时，图片将选取部分展示</div>
                </el-form-item>
                  <el-form-item label="自定义分享文案" v-if="formFormatData.formData.couponData.wxapp_share==1">
                      <el-input  placeholder="请输入分享文案" v-model="formFormatData.formData.couponData.custom_share_content" width="50">
                      </el-input>
                </el-form-item>
        </el-form>
      </div>
    </div>

    <div class="wlm-form">
      <div class="wlm-form-header">领取使用</div>
      <div class="wlm-form-content">
        <el-form ref="use" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
          <el-form-item label="适用商品">
            <el-radio-group @change="chooseGoodsChange" v-model="formFormatData.formData.couponData.suit_goods_type" class="wlm-form-group flex-col" style="width:100px;">
              <el-radio :label="0">
                全部商品可用
              </el-radio>
              <el-radio :label="1">
                部分商品可用
              </el-radio>
              <el-radio :label="2">
                部分商品不可用
              </el-radio>
              <el-radio :label="3">
                            指定商品分类
                        </el-radio>
                          <el-radio :label="4">
                            指定商家可用
                        </el-radio>
            </el-radio-group>
            <el-select v-model="formFormatData.formData.category_name" multiple @remove-tag="removeTag" collapse-tags placeholder="请选择"
             v-if="formFormatData.formData.couponData.suit_goods_type=='3'">
                        <el-option style="height:auto;padding: 0;" key="key" label="label" value="value" v-if="categoryData.length>0">
                          <div class="category-tree">
                            <el-tree
                                ref="trees"
                                @check="checkChange"
                                :default-checked-keys="formFormatData.formData.category_id"
                                node-key="category_id"
                                highlight-current
                                :props="{label: 'name',children: 'child',isLeaf: 'leaf'}"
                                :data="categoryData"
                                show-checkbox></el-tree>
                          </div>
                        </el-option>
                      </el-select>
                      <el-select
                      v-if="formFormatData.formData.couponData.suit_goods_type=='4'"
                          :disabled="!!formFormatData.api['editForm']['params']['id']"
                          filterable
                          multiple 
                          v-model="formFormatData.formData.bus_id"
                          placeholder="请选择或输入关键词搜索"
                          >
                        <el-option v-for="item in shopData" :disabled="item.storenum==0" :key="item.value" :label="item.name" :value="item.id"></el-option>
                      </el-select>

          </el-form-item>
          <el-form-item label="" prop="suit_goods" v-if="formFormatData.formData.couponData.suit_goods_type!=3&& formFormatData.formData.couponData.suit_goods_type!=0 && formFormatData.formData.couponData.suit_goods_type!=4">
            <choose-goods ref="chooseGoods" :config="chooseGoodsConfig" :changeEvt="formFormatFiltersChangebtn"></choose-goods>
                     <el-button type="primary" @click="goodsToogle">选择商品</el-button>
                            <div style="height:10px;"></div>
                            <el-table v-if="formFormatData.formData.suit_goods != ''" :data="formFormatData.formData.suit_goods" style="width: 100%;">
                                <el-table-column  label="商品">
                                    <template slot-scope="scope">
                                        <div v-for="(item,index) in scope.row.goods" :key="index"> 
                                        <div class="flex-row">
                                         <img class="logo" v-if="item.image" :src="item.image[0]['file_path']">
                                        <div class="inner-text">
                                        <p>{{item.goods_name}}</p>
                                        </div>
                                    </div>
                                    </div>
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                    <div class="operation-group">
                                        <el-button  class="wlm-text" type="text" @click="deleteTable(scope)">删除</el-button>
                                    </div>
                                    </template>
                                </el-table-column>
                            </el-table>
          </el-form-item>
          <!-- <el-form-item label="首页是否展示">
                       <el-radio-group v-model="formFormatData.formData.couponData.first_page">
                        <el-radio :label="1">
                            展示
                        </el-radio>
                        <el-radio :label="2">
                            隐藏
                        </el-radio>
                    </el-radio-group>
                  </el-form-item> -->
                  <el-form-item label="领劵中心展示">
                       <el-radio-group v-model="formFormatData.formData.couponData.coupon_core">
                        <el-radio :label="1">
                            展示
                        </el-radio>
                        <el-radio :label="2">
                            隐藏
                        </el-radio>
                    </el-radio-group>
                  </el-form-item>
          <el-form-item label="展示在商品详情">
            <el-radio-group v-model="formFormatData.formData.is_show">
              <el-radio :label="0">
                不展示
              </el-radio>
              <el-radio :label="1">
                展示
              </el-radio>
            </el-radio-group>
            <p class="form-help">展示在商品详情后，用户可以直接领取</p>
          </el-form-item>
          <el-form-item label="领取人限制">
            <el-radio-group v-model="formFormatData.formData.couponData.get_limit_type" class="wlm-form-group flex-col">
                        <el-radio :label="0">所有人均可领取</el-radio>
                        <el-radio :label="1">会员可领取</el-radio>
                        <el-radio :label="2">指定标签用户</el-radio>
                    </el-radio-group>
              <el-select multiple v-model="formFormatData.formData.tag_id" filterable placeholder="请选择" v-if="formFormatData.formData.couponData.get_limit_type=='2'">
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
          </el-form-item>
          <el-form-item label="领取次数" prop="couponData.limit_num" :rules="[{ required: formFormatData.formData.couponData.get_limit_num_type === 1, message: '请输入领取次数', trigger: 'blur' }]">
            <el-radio-group v-model="formFormatData.formData.couponData.get_limit_num_type" class="wlm-form-group flex-col">
              <el-radio :label="0">不限次数</el-radio>
              <el-radio :label="2">
                每天最多领取
                <el-input-number style="width:50px;" class="wlm-input-auto" v-model.trim="formFormatData.formData.couponData.limit_num" :controls="false" :min="0" :precision='0'>
                </el-input-number>
                次
              </el-radio>
              <el-radio :label="1">
                最多领取
                <el-input-number style="width:50px;" class="wlm-input-auto" v-model.trim="formFormatData.formData.couponData.limit_num" :controls="false" :min="0" :precision='0'>
                </el-input-number>
                次
              </el-radio>
              <el-radio :label="3">
                          每月可领取
                          <!-- <el-input style="width:50px;" v-model.trim="formFormatData.formData.couponData.limit_num">
                          </el-input> -->
                          <el-input-number style="width:50px;"  class="wlm-input-auto" v-model.trim="formFormatData.formData.couponData.limit_num" :controls="false" :min="0" :precision='0'>
                            </el-input-number>
                          张
                        </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="使用说明">
            <el-input type="textarea" v-model="formFormatData.formData.couponData.use_desc" :autosize="{ minRows: 4, maxRows: 4}">
            </el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
      <el-button size="small" @click="saveForm" type="primary">保存</el-button>
      <router-link tag="span" to="/application/couponMarketing">
        <el-button size="small">返回</el-button>
      </router-link>
    </div>
  </div>
</template>

<script>
import {
  couponEditOrAdd,
  couponDetail,
  getUserTag
} from '@/api/application'
import {
  businessIndex,
} from '@/api/merchant'
import { Base64 } from 'js-base64'
import { checkNumberAnddDecimal, checkPositiveInteger } from '@/utils/validate.js'
import ChooseGoods from '@/components/ChooseGoods/index'
import ChooseFiles from '@/components/ChooseFiles/index'
import mixins from '@/mixins/mixins'
import {
  regPrice
} from '@/utils/regular'
import {
  categoryIndex,
} from '@/api/merchandise'
const checkArray = (rule, value, callback) => {
  const { message } = rule
  if (!Array.isArray(value) || (Array.isArray(value) && value.length === 0)) {
    return callback(new Error(`${message}！~`))
  } else {
    callback()
  }
}
export default {
  mixins: [mixins.getters('Form')],
  name: 'ManagementUserAdd',
  components: {
    ChooseGoods,
    ChooseFiles
  },
  directives: {

  },
  created(){
    this.$nextTick(() => {
       this.categoryGet()
    this.luck_crowdbtn()
    this.shopDataGet()
    })
  },
  data() {
    var checkDiscount = (rule, value, callback) => {
      const val = this.formFormatData.formData.couponData.discount
      if (val === '') {
        return callback(new Error('请添写优惠内容'))
      } else if (!regPrice(val) || (val <= 0 || val >= 10)) {
        return callback(new Error('优惠折扣有误,请修改后提交'))
      } else {
        callback()
      }
    }
    return {
      currentRow:[],
      defaultMsg: '',
      options:[],
      shopData:[],
      categoryData:[],
      // pickerOptions: {
      //   disabledDate(time) {
      //     const $date = new Date()
      //     const year = $date.getFullYear()
      //     const month = $date.getMonth() + 1
      //     const day = $date.getDate()
      //     return time.getTime() < new Date(`${year}/${month}/${day}`)
      //   }
      // },
      chooseGoodsConfig: {
       type: ['chooseGoods'],
        initList: [],
       model: 'normal',
                unique: false,
                thumbtn: 'thumbtns',
                initList: [],
      },
      choosePlatformConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isMore: true,
          model: 'display'
        },
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'coupon_image',
          model: 'img'
        }
      },
      chooseBgConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isMore: true,
          model: 'display'
        },
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'share_image_id',
          model: 'img'
        }
      },
      formFormatData: {
        key: ['base', 'use'],
        api: {
          editForm: {
            api: couponDetail,
            params: {
              id: ''
            },
            redirect: 'couponId',
            filters: {
              choose: {
                bindInit: ['chooseGoodsConfig']
              },
              img:{
                bindInit:['choosePlatformConfig']
              }
            },
            noFilter: ['category_name']
          },
          submitForm: couponEditOrAdd
        },
        formData: {
          bus_id: [],
          couponId: '',
          is_show: 0,
          coupon_image:[],
          couponData: {
              // first_page:1,
          coupon_core:1,
             wxapp_share:2,
            custom_share_content:'',
            coupon_type: 20,
            name: '',
            total_num: '',
            // is_share:2,
            limit_num:'',
            // share_receive:2,
            expire_day:'',
            vice_name:'',
            sort:'',
            discount: '',
            source: [],
            expire_type: 10,
            limit_time: [],
            max_price_type: 0,
            expire_day: '',
            rule: 1,
            rule_min_money: '',
            suit_goods_type: 0,
            get_limit_type: 0,
            limit_num: '',
            use_desc: '',
            get_limit_num_type: 0
          },
          suit_goods: [],
          tag_id:[],// 标签
          category_id:[],
          category_name:[],
        },
        rules: {
          couponData: {
            discount: [{
              required: true,
              validator: checkDiscount,
              trigger: 'change'
            }],
            rule_min_money: [
              { required: true, message: '请输入消费门槛', trigger: 'blur' },
              {
                message: '请输入正确的消费门槛',
                validator: checkNumberAnddDecimal,
                trigger: ['blur', 'change']
                
              }
              ],
            total_num: [
              { required: true, message: '请输入发放总数', trigger: 'blur' }, {
                message: '请输入正确的发放总数',
                validator: checkPositiveInteger,
                trigger: ['blur', 'change']
              }]
          },

          suit_goods: [{
            message: '请选择适用商品',
            required: false,
            validator: checkArray,
            trigger: 'blur'
          }]
        }
      }
    }
  },
  methods: {
    shopDataGet() {
      businessIndex({ list_rows: 'all' }).then((response) => {
        const { data: { data: msgData = [] } } = response
        this.shopData = msgData
      })
   
    },
    //控制商品弹出框的显示
          goodsToogle() {
             const result = []
       this.formFormatData.formData.suit_goods.map(item => {
        result.push(Number(item.goods_id))
      })
      this.$refs.chooseGoods.currentRow = result
              
              this.$refs.chooseGoods.toggle()
          },
          //   构造商品信息
    formFormatFiltersChangebtn(val){
      this.currentRow = val.currentRow
      const displayData = val.displayData
            const result = []
        displayData.map(item=>{

           const newData = { image: [{ file_path: item.image[0]['file_path'] }],goods_name: item.goods_name, goods_id: item.goods_id, stock_num: item.stock, goods_price: item.goods_min_price }
         result.push({ goods:[newData], goods_id: item.goods_id })
        })   
       this.formFormatData.formData.suit_goods.push(...result)
    },
    //  删除选中的商品
          deleteTable(scope) {
            this.formFormatData.formData.suit_goods.splice(scope.$index, 1)
            this.currentRow.splice(scope.$index, 1)
          },
    categoryGet() {
      categoryIndex().then((response) => {
        const { data: { data: msgData = [] } } = response
        this.categoryData = msgData
        console.log("oooooooooooooooooooooooo",this.categoryData)
      })
    },
    removeTag(tag) {
      this.formFormatData.formData.category_id.splice(0, 1)
      this.$refs.trees.setCheckedKeys(this.formFormatData.formData.category_id)
    },
    checkChange(check, checkedNodes) {
      console.log(check, 'check')
      console.log(checkedNodes, 'checkedNodes')
      console.log(this.category_name, 'this.category_name')
      this.formFormatData.formData.category_id = checkedNodes.checkedKeys
      console.log("99999999999999999999999999999",this.formFormatData.formData.category_id)
      const result = []
      checkedNodes.checkedNodes.map(item => {
        result.push(item.name)
      })
      console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxx",result)
      this.formFormatData.formData.category_name = result
    },
    // 点击标签用户请求接口
    luck_crowdbtn() {
      getUserTag().then(res => {
        const { data: { data: msgData = [] } } = res
        this.options = msgData
      })
    },
    saveForm() {
      if (this.formFormatData.formData.couponData.name == '') {
        this.$message.error('请输入优惠券名称！')
        return
      }
      if (this.formFormatData.formData.couponData.total_num == '') {
        this.$message.error('请输入发放总数！')
        return
      }
        if (this.formFormatData.formData.couponData.expire_type == 10 && (this.formFormatData.formData.couponData.limit_time=='')) {
        this.$message.error('请选择使用时间！')
        return
      }
        if (this.formFormatData.formData.couponData.discount == '') {
        this.$message.error('请输入优惠内容！')
        return
      }
      if (this.formFormatData.formData.couponData.source == '') {
        this.$message.error('请选择发放渠道！')
        return
      }
       if (this.formFormatData.formData.couponData.suit_goods_type==1 && (this.formFormatData.formData.suit_goods =='')) {
        this.$message.error('请选择适用商品！')
        return
      }
      if (this.formFormatData.formData.couponData.suit_goods_type==2 && (this.formFormatData.formData.suit_goods =='')) {
        this.$message.error('请选择适用商品！')
        return
      }
      if (this.formFormatData.formData.couponData.suit_goods_type==3 && (this.formFormatData.formData.category_name=='')) {
        this.$message.error('请选择商品分类！')
        return
      }
      if (this.formFormatData.formData.couponData.suit_goods_type==4 && (this.formFormatData.formData.bus_id=='')) {
        this.$message.error('请选择指定商家！')
        return
      }
      const data = Base64.encode(JSON.stringify(this.formFormatData.formData))
      couponEditOrAdd({data:data}).then(res=>{
         const { data: { code } } = res
         if(code ===1){
           this.$message({
            type: 'success',
            message: '保存成功!'
          })
           this.$router.push({ path: '/application/couponMarketing' })
         }else{
            this.$message.error(msg)
         }
      })
      if (this.couponId !== '' && (this.formFormatData.formData.couponData.suit_goods_type !== 0)) {
        this.$refs.chooseGoods.output()
      } else {
        this.formFormatData.formData.suit_goods = []
      }
      // this.formFormatSubmit({ router: { type: 'replace', path: '/application/couponMarketing', code: 1 } })
    },
    chooseGoodsChange(val) {
      if (val == 0) {
        this.formFormatData.rules.suit_goods = [{
          message: '请选择适用商品',
          required: false,
          trigger: 'change'
        }]
      } else {
        this.formFormatData.rules.suit_goods = [{
          message: '请选择适用商品',
          required: true,
          validator: checkArray,
          trigger: 'change'
        }]
      }
      if(val ==0 && val ==3){
        this.formFormatData.formData.suit_goods = []
      }
      if(val ==4){
       this.formFormatData.formData.category_name= []
       this.formFormatData.formData.category_id=[]
      }
      if(val ==3){
        this.formFormatData.formData.bus_id= []
      }
      // formFormatData.formData.couponData.suit_goods_type
      console.log("++++++++++++",this.formFormatData.formData.suit_goods )
    },
    infoChange(msg) {
      this.formFormatData.formData.couponData.use_desc = msg
    },
    formFormatCallBack(data, type, response) {
      if (type === 'editForm') {
        const { data: { data: { couponData: { use_desc = '' } } } } = response
        this.defaultMsg = use_desc
      } else if (type === 'editBeforeForm') {
        const { couponData: { source } } = data
        if (!Array.isArray(source)) {
          data.couponData.source = []
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.serving-merchandise-add {
}
</style>
